﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.ApplicationBlocks.Data;
using TransportManager.UI.Pages;
namespace TransportManager.Web.Admin
{
    /// <summary>
    /// PasswordModify 的摘要说明。
    /// </summary>
    public class PasswordModify2 : Page
    {
        protected System.Data.DataTable dt;
        protected String Sqlstr;
        protected System.Web.UI.WebControls.TextBox tbuser;
        protected System.Web.UI.WebControls.TextBox tbold;
        protected System.Web.UI.WebControls.TextBox tbnew;
        protected System.Web.UI.WebControls.TextBox tbnew1;
        protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
        protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
        protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
        protected System.Web.UI.WebControls.CompareValidator CompareValidator1;
        protected System.Web.UI.WebControls.Label lbMessage;
        protected System.Web.UI.WebControls.TextBox tbNewuser;
        protected System.Web.UI.WebControls.HyperLink hyBack;
        protected System.Web.UI.WebControls.Button Button1;

        private void Page_Load(object sender, System.EventArgs e)
        {
            if (Page.IsPostBack) return;
        }

        #region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.Button1.Click += new System.EventHandler(this.Button1_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        private void Button1_Click(object sender, System.EventArgs e)
        {
            Sqlstr = " if exists(select * from purview_user where username='" + tbuser.Text.Trim() + "' and password ='" + tbold.Text.Trim() + "')  begin ";
            if (tbNewuser.Text.Trim() == "")
                Sqlstr += " update purview_user set password ='" + tbnew.Text.Trim() + "' where username='" + tbuser.Text.Trim() + "'";
            else
                Sqlstr += " update purview_user set password ='" + tbnew.Text.Trim() + "',username='" + tbNewuser.Text.Trim() + "'  where username='" + tbuser.Text.Trim() + "'";
            Sqlstr += " ;select 1; end else select 2;";
            dt = SqlHelper.ExecuteDataset(Session["Conn"].ToString(), CommandType.Text, Sqlstr).Tables[0];
            if (dt.Rows[0][0].ToString() == "2")
            {
                lbMessage.Text = "用户名错误，或者原密码错误。";
                lbMessage.Visible = true;
            }
            else
                Response.Redirect("../Login.aspx");

        }
    }
}
